package com.v2future.sjt.collegecheckingattendance.rollcall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.rollcall.bean.SubjectBean;

import java.util.List;

/**
 * Created by minnie on 16/1/20.
 */
public class SubjectAdapter extends BaseAdapter{

    List<SubjectBean> dataList;
    Context mContext;

    public SubjectAdapter(Context context, List<SubjectBean> dataList) {
        mContext = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        final SubjectBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_text_check, null);
            holder = new ViewHolder();
            holder.subjectTv = (TextView) convertView.findViewById(R.id.tv_key);
            holder.selectCb = (CheckBox) convertView.findViewById(R.id.cb_select);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.subjectTv.setText(bean.getCourseName());
        holder.selectCb.setChecked(bean.isChecked());
        return convertView;
    }

    public class ViewHolder {
        TextView subjectTv;
        CheckBox selectCb;
    }
}
